package com.hdoit.ares.logical.personnel.dao.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import com.hdoit.ares.logical.personnel.dao.IPersonnelDao;
import com.hdoit.ares.logical.personnel.model.Personnel;
import com.hdoit.ares.logical.viewmodel.personnel.PersonnelSearch;
import com.tennetcn.common.dao.base.IFinderExpression;
import com.tennetcn.common.dao.base.impl.SuperDao;
import com.tennetcn.common.enums.OrderEnum;
import com.tennetcn.common.logical.superbase.model.Employee;
import com.tennetcn.common.message.PagerModel;
import com.tennetcn.common.utils.FinderExpressionFactory;

/**
 * @author      caochengmeng
 * @email       
 * @createtime  2017年11月15日 10:09:24
 * @comment
 */
@Component
public class PersonnelDaoImpl extends SuperDao<Personnel> implements IPersonnelDao{

	@Override
	public List<Personnel> queryList(PersonnelSearch personnelSearch, PagerModel pagerModel,String employeeAccount) {
		
		IFinderExpression businessIdFinder = FinderExpressionFactory.createExpression();
		businessIdFinder.select("businessId")
						.from(Employee.class)
						.andWhere("employeeAccount=#{employeeAccount}");
		
		IFinderExpression childFinder = FinderExpressionFactory.createExpression();
		childFinder.select("employeeId")
						.from(Employee.class)
						.andWhere("businessId = ("+businessIdFinder.toSql()+")");
		
		IFinderExpression finderExpression=FinderExpressionFactory.createExpression();
		finderExpression.select("*")
						.from(Personnel.class)
						.andWhere("employeeId in ("+childFinder.toSql()+")")
						.setParam("employeeAccount", employeeAccount)
						.addOrder("joinUsDate", OrderEnum.asc);
		return queryList(finderExpression, personnelSearch, pagerModel);
	}

}
